(function($){
	$.fn.ZTable = function(options){
		var settings = $.extend({
			//Default options
			select_row_cb: function($Row){},
			row_height: 64
		}, options);
		
		function getCheckbox(){
			//Deprecated function
			checkboxes = $('input:checked');
			id = $(checkboxes[0]).val();
			$selected = $('tr[value="' + id +'"]');
		}
		
		this.getMode = function(){
			return this.attr('mode');
		}
		
		this.setMode = function(mode){
			//Argument:
			// mode --- 'normal' or 'edit'
			return this.attr('mode', mode);
		}
		
		this.getHighlightedRow = function(){
			return $(this).find('.highlight');
		}
		
		this.select_row = function($Row){
			$Row.addClass('highlight').siblings().removeClass('highlight');

	     	$checkbox = $Row.find('input[name="selected"]');
	    	if($checkbox.is(':checked')){
	    		$checkbox.prop('checked', false);
	    	}else{
	    		$checkbox.prop('checked', true);
			}
		    settings.select_row_cb( $Row );
		}
		
		this.append_row = function(row){
			this.find('tbody').append(row);
		}
		
		// Initialization
		table = this;
		
		// Set row select handler
		this.find( 'tbody > tr').click( function(event) {
		    if (event.target.type == 'checkbox'){
		    	$(this).addClass('highlight').siblings().removeClass('highlight');
		    	event.stopPropagation();
		    	settings.select_row_cb( $(this) );
		    }else{
		    	table.select_row($(this));
		    } 	
		});
		
		// Set checkbox handler
		this.find('input[name="selected"]:checked').click(function(){
			$(this).prop('checked', false);	
		});

		this.clear = function(){
			$(this).find('tbody').html('');
		}
		
		this.find( 'tbody > tr').height(settings.height)
		
		return this;

	}//End of ZTable
	
}(jQuery));